<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActionController::Assertions</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActionController::Assertions</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/actionpack/lib/action_controller/assertions/dom_assertions_rb.html">
                vendor/rails/actionpack/lib/action_controller/assertions/dom_assertions.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/actionpack/lib/action_controller/assertions/model_assertions_rb.html">
                vendor/rails/actionpack/lib/action_controller/assertions/model_assertions.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/actionpack/lib/action_controller/assertions/response_assertions_rb.html">
                vendor/rails/actionpack/lib/action_controller/assertions/response_assertions.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/actionpack/lib/action_controller/assertions/routing_assertions_rb.html">
                vendor/rails/actionpack/lib/action_controller/assertions/routing_assertions.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/actionpack/lib/action_controller/assertions/selector_assertions_rb.html">
                vendor/rails/actionpack/lib/action_controller/assertions/selector_assertions.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/actionpack/lib/action_controller/assertions/tag_assertions_rb.html">
                vendor/rails/actionpack/lib/action_controller/assertions/tag_assertions.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/actionpack/lib/action_controller/assertions_rb.html">
                vendor/rails/actionpack/lib/action_controller/assertions.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
In addition to these specific assertions, you also have easy access to
various collections that the regular test/unit assertions can be used
against. These collections are:
</p>
<ul>
<li>assigns: Instance variables assigned in the action that are available for
the view.

</li>
<li>session: Objects being saved in the session.

</li>
<li>flash: The flash objects currently in the session.

</li>
<li>cookies: <a href="Cookies.html">Cookies</a> being sent to the user on this
request.

</li>
</ul>
<p>
These collections can be used just like any other hash:
</p>
<pre>
  assert_not_nil assigns(:person) # makes sure that a @person instance variable was set
  assert_equal &quot;Dave&quot;, cookies[:name] # makes sure that a cookie called :name was set as &quot;Dave&quot;
  assert flash.empty? # makes sure that there's nothing in the flash
</pre>
<p>
For historic reasons, the assigns hash uses string-based keys. So
assigns[:person] won&#8216;t work, but assigns[&quot;person&quot;] will. To
appease our yearning for symbols, though, an alternative accessor has been
devised using a method call instead of index referencing. So
assigns(:person) will work just like assigns[&quot;person&quot;], but
again, assigns[:person] will not work.
</p>
<p>
On top of the collections, you have the complete url that a given action
redirected to available in redirect_to_url.
</p>
<p>
For redirects within the same controller, you can even call follow_redirect
and the redirect will be followed, triggering another action call which can
then be asserted against.
</p>
<h2>Manipulating the request collections</h2>
<p>
The collections described above link to the response, so you can test if
what the actions were expected to do happened. But sometimes you also want
to manipulate these collections in the incoming request. This is really
only relevant for sessions and cookies, though. For sessions, you just do:
</p>
<pre>
  @request.session[:key] = &quot;value&quot;
</pre>
<p>
For cookies, you need to manually create the cookie, like this:
</p>
<pre>
  @request.cookies[&quot;key&quot;] = CGI::Cookie.new(&quot;key&quot;, &quot;value&quot;)
</pre>
<h2>Testing named routes</h2>
<p>
If you&#8216;re using named routes, they can be easily tested using the
original named routes&#8217; methods straight in the test case. Example:
</p>
<pre>
 assert_redirected_to page_url(:title =&gt; 'foo')
</pre>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000353">clean_backtrace</a>&nbsp;&nbsp;
      <a href="#M000352">included</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Module <a href="Assertions/DomAssertions.html" class="link">ActionController::Assertions::DomAssertions</a><br />
Module <a href="Assertions/ModelAssertions.html" class="link">ActionController::Assertions::ModelAssertions</a><br />
Module <a href="Assertions/ResponseAssertions.html" class="link">ActionController::Assertions::ResponseAssertions</a><br />
Module <a href="Assertions/RoutingAssertions.html" class="link">ActionController::Assertions::RoutingAssertions</a><br />
Module <a href="Assertions/SelectorAssertions.html" class="link">ActionController::Assertions::SelectorAssertions</a><br />
Module <a href="Assertions/TagAssertions.html" class="link">ActionController::Assertions::TagAssertions</a><br />

    </div>

    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">NO_STRIP</td>
          <td>=</td>
          <td class="context-item-value">%w{pre script style textarea}</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000352" class="method-detail">
        <a name="M000352"></a>

        <div class="method-heading">
          <a href="#M000352" class="method-signature">
          <span class="method-name">included</span><span class="method-args">(klass)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000352-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000352-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/assertions.rb, line 46</span>
46:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">included</span>(<span class="ruby-identifier">klass</span>)
47:       <span class="ruby-node">%w(response selector tag dom routing model)</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">kind</span><span class="ruby-operator">|</span>
48:         <span class="ruby-identifier">require</span> <span class="ruby-node">&quot;action_controller/assertions/#{kind}_assertions&quot;</span>
49:         <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">module_eval</span> { <span class="ruby-identifier">include</span> <span class="ruby-identifier">const_get</span>(<span class="ruby-node">&quot;#{kind.camelize}Assertions&quot;</span>) }
50:       <span class="ruby-keyword kw">end</span>
51:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000353" class="method-detail">
        <a name="M000353"></a>

        <div class="method-heading">
          <a href="#M000353" class="method-signature">
          <span class="method-name">clean_backtrace</span><span class="method-args">() {|| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000353-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000353-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/assertions.rb, line 53</span>
53:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clean_backtrace</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
54:       <span class="ruby-keyword kw">yield</span>
55:     <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Test</span><span class="ruby-operator">::</span><span class="ruby-constant">Unit</span><span class="ruby-operator">::</span><span class="ruby-constant">AssertionFailedError</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">error</span>
56:       <span class="ruby-identifier">framework_path</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-node">&quot;#{File.dirname(__FILE__)}/assertions&quot;</span>))
57:       <span class="ruby-identifier">error</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">reject!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">line</span>) <span class="ruby-operator">=~</span> <span class="ruby-identifier">framework_path</span> }
58:       <span class="ruby-identifier">raise</span>
59:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>